<template>
  <div class="container">
<!--      <view v-for="(item,index) in orders" v-bind:key="index">-->
<!--        <text>{{item.date}}</text>-->

<!--      </view>-->
    <van-cell v-for="(item,index) in orders" v-bind:key="index" center title="就餐" :value="item.totalPrice" :label="item.createDate" >
        {{item}}
    </van-cell>
  </div>
</template>

<script>
  export default {
    data(){
      return {
        orders:[]
      }
    },
    methods:{
       getHistoryByName(name = 'empiricism'){
        const db = wx.cloud.database({env: 'jkoala-98c74'});
        const $ = db.command.aggregate
         db.collection('orders').where({
           name:"empiricism"
         }).get().then(res=>{
           console.log(res.data);
           //处理日期
           // new Date().toLocaleDateString()
            let tempHistory = []
           for(let key in res.data){
             res.data[key].createDate = this.dateFormat(res.data[key].createDate)
             // tempHistory.push(item);
           }
           this.orders = res.data;
         })

      },
      dateFormat(time){
        return `${time.getFullYear()}-${time.getMonth() + 1 >= 10 ? (time.getMonth() + 1):'0' + (time.getMonth() + 1)}-${time.getDate() >= 10 ? time.getDate():'0' + time.getDate()} ${time.getHours() >= 10 ? time.getHours():'0' + time.getHours()}:${time.getMinutes()>=10?time.getMinutes():'0'+time.getMinutes()}:${time.getSeconds() >= 10 ? time.getSeconds():'0' + time.getSeconds()}`;
      }
    },
    mounted(){
      this.getHistoryByName();
    }
  }

</script>

<style>
  .pay-image{

  }
  .van-image{
    margin: 10px auto;
  }
</style>
